﻿using SqlSugar;
using System.Collections.Generic;

/*!
 * 文件描述：一切从简，只为了更懒！
 */

namespace App.ORM
{
    public partial class SqlSugarInstance
    {
        #region 构造：无参构造函数，禁止实例化 + public SqlSugarInstance()
        /// <summary>
        /// 禁止实例化
        /// </summary>
        public SqlSugarInstance()
        {
        }
        #endregion

        #region 静态：获取Sugar客户端实例对象 + public static SqlSugarClient GetInstance()
        /// <summary>
        /// 获取Sugar客户端实例对象
        /// </summary>
        /// <returns>SqlSugarClient</returns>
        public static SqlSugarClient GetInstance()
        {
            string connection = System.Configuration.ConfigurationManager.ConnectionStrings[@"AppAit.IO_ConnStr"].ToString();

            SqlSugarClient _SqlSugarClient = new SqlSugarClient(new ConnectionConfig() {
                ConnectionString = connection,//必填, 数据库连接字符串

                DbType = DbType.MySql,         //必填, 数据库类型

                IsAutoCloseConnection = true,       //默认false, 时候知道关闭数据库连接, 设置为true无需使用using或者Close操作

                InitKeyType = InitKeyType.SystemTable    //默认SystemTable, 字段信息读取, 如：该属性是不是主键，是不是标识列等等信息
            });

            // 映射表，解决类名和表名不一致情况，通常体现在表名加前缀，类名不加
            //_SqlSugarClient.SetMappingTables(_MappingTables);
            _SqlSugarClient.MappingTables.AddRange(_MappingTables);
            return _SqlSugarClient;
        }
        #endregion
    }
}
